home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / CDTV / cdtvtools-11 / keeper / pickeeper.asm < prev    next >
Encoding:
Assembly Source File  |  1991-06-24  |  6.0 KB  |  242 lines

  1. *****************************************************************************
  2. *
  3. *    pickeeper.asm -- written by Ray Lambert for Theta Systems, Inc.
  4. *
  5. *    Copyright 1991 Commodore Business Machines, Inc.
  6. *
  7. *****************************************************************************
  8.  
  9.  
  10.         INCLUDE        "keeper.i"
  11.         INCLUDE        "libraries/dos.i"
  12.         INCLUDE        "graphics/gfx_equ.i"
  13.         INCLUDE        "graphics/gfxbase.i"
  14.         INCLUDE        "graphics/gfx.i"
  15.         INCLUDE        "graphics/view.i"
  16.         INCLUDE        "exec/tasks.i"
  17.         INCLUDE        "exec/memory.i"
  18.         INCLUDE        "hardware/custom.i"
  19.         INCLUDE        "hardware/dmabits.i"
  20.         INCLUDE        "intuition/intuition_equ.i"
  21.  
  22.  
  23. STKSIZE        EQU        4096
  24.  
  25.  
  26. DISPLAY_ON    MACRO
  27.         move.w        #DMAF_SETCLR|DMAF_RASTER,CHIPBASE+dmacon
  28.         ENDM
  29.  
  30. SPRITES_ON    MACRO
  31.         move.w        #DMAF_SETCLR|DMAF_SPRITE,CHIPBASE+dmacon
  32.         ENDM
  33.  
  34. SPRITES_OFF    MACRO
  35.         move.w        #DMAF_SPRITE,CHIPBASE+dmacon
  36.         ENDM
  37.  
  38.  
  39.  
  40.         SECTION        text,code
  41.  
  42.  
  43.         FUNCTION    _keeper,0,d2/a3/a4/a6
  44.         ARGUMENTS
  45.         ARG        _APTR,view
  46.         ARG        _APTR,memlist
  47.  
  48. * allocate memory for task
  49.         lea        tcbmem,a0
  50.         jsrsys        AllocEntry
  51.         bclr.l        #31,d0            ; if this bit is set
  52.         bne        fail            ; the alloc. failed
  53.  
  54. * get pointers to newly allocated stack and TCB
  55. * register usage
  56. * d2 = allocated memlist
  57. * a5 = argument pointer (stack frame)
  58. * a4 = code ptr (initPC)
  59. * a3 = TCB
  60. * a2 = stack
  61.         move.l        d0,d2            ; save memlist in d2
  62.         move.l        d0,a1
  63.         add.l        #ML_ME,a1        ; ptr to 1st ME
  64.         move.l        ME_ADDR(a1),a2        ; get pointer to stack
  65.         add.l        #ME_SIZE,a1        ; get ptr to 2nd ME
  66.         move.l        ME_ADDR(a1),a3        ; get pointer to TCB
  67.         add.l        #ME_SIZE,a1        ; get ptr to 3rd ME
  68.         move.l        ME_ADDR(a1),a4        ; get pointer to code
  69.  
  70. * initialize stack and TCB stuff
  71. * TCB node...
  72.         move.b        #NT_TASK,LN_TYPE(a3)    ; store node type
  73.         move.b        #5,LN_PRI(a3)        ; store node priority
  74.         move.l        a2,LN_NAME(a3)        ; store name in TCB node
  75. * task name...
  76.         lea        name,a1            ; ptr to original name
  77.         move.l        #endname-name-1,d0    ; length of name (-1 for dbra)
  78. 1$        move.b        (a1)+,(a2)+        ; copy all bytes (including 0)
  79.         dbra        d0,1$            ;  to stack bottom
  80. * TCB stack info...
  81.         move.l        a2,a0            ; calc SPUPPER
  82.         add.l        #STKSIZE,a0
  83.         move.l        a0,TC_SPUPPER(a3)    ; store SPUPPER in TCB
  84. * push data we pass to new task
  85.         move.l        view(a5),-(a0)        ; push View ptr and
  86.         move.l        _GfxBase,-(a0)        ;  gfxbase and 
  87.         move.l        _IntuitionBase,-(a0)    ;  intuitionbase on task's stack
  88. * more TCB stack info...
  89.         move.l        a0,TC_SPREG(a3)        ; store SP in TCB
  90.         move.l        a2,d0
  91.         addq.l        #3,d0            ; round SPLOWER up
  92.         and.l        #~3,d0            ; stack = ((stack+3)&~3)
  93.         move.l        d0,TC_SPLOWER(a3)    ; store SPLOWER in TCB
  94.  
  95. * initialize TCB mem list...
  96.         lea        TC_MEMENTRY(a3),a0    ; ptr to mem list
  97.         NEWLIST        a0
  98.         move.l        d2,a1            ; our mem list
  99.         jsrlib        AddHead
  100.         lea        TC_MEMENTRY(a3),a0    ; ptr to mem list
  101.         move.l        memlist(a5),a1        ; caller's mem list
  102.         jsrlib        AddHead
  103.  
  104. * copy task code...
  105.         move.l        a4,a1            ; new segment
  106.         lea        keeper_task,a0        ; original code
  107.         move.l        #kt_end-keeper_task-1,d0; size of segment (-1 for dbra)
  108. 2$        move.b        (a0)+,(a1)+        ; copy code segment
  109.         dbra        d0,2$
  110.  
  111. * add the task...
  112.         move.l        a3,a1            ; TCB
  113.         move.l        a4,a2            ; initPC
  114.         move.l        #0,a3            ; finalPC (0)
  115.         jsrlib        AddTask
  116.  
  117.         moveq        #1,d0
  118.         bra        99$
  119. fail
  120.         moveq        #0,d0
  121. 99$
  122.         RETURN        _keeper
  123.  
  124.  
  125. ***********************************************************************
  126. *       This is the code for the task we detach and spawn
  127. ***********************************************************************
  128.         CNOP        0,4
  129. keeper_task
  130.         XDEF        keeper_task    ; for debugging reference
  131.         ARGUMENTS
  132.         ARG        _APTR,ibase
  133.         ARG        _APTR,gfxbase
  134.         ARG        _APTR,view
  135.         LOCAL_STACK
  136. *        AUTO        _APTR,oldview
  137.  
  138. * use a5 for stack frame pointer
  139.         link        a5,#-SFSIZE
  140.  
  141. * show our view
  142.         move.l        gfxbase(a5),a6
  143. *        move.l        gb_ActiView(a6),oldview(a5); save the old view
  144. 9$        move.l        view(a5),a1
  145.         jsrlib        LoadView
  146.  
  147. * blank the mousey (turn sprite DMA off) and ensure that display DMA is on
  148. 10$        jsrlib        WaitTOF        ; wait till vertical blank
  149.         SPRITES_OFF
  150.         DISPLAY_ON
  151.  
  152. * wait until it's time to remove our view
  153. 1$        move.l        #29,d7        ; wait for 1/2 second (30-1)
  154.         move.l        gfxbase(a5),a6
  155. 2$        jsrlib        WaitTOF
  156.         dbra        d7,2$
  157.         move.l        gb_ActiView(a6),d0; check if the ActiView has changed
  158.         beq        9$        ; reload our view if this is NULL
  159.         cmp.l        view(a5),d0
  160.         bne        4$        ; new view is now visible
  161.         moveq        #0,d0        ; check if a CTRL-C has arrived
  162.         moveq        #0,d1
  163.         jsrsys        SetSignal
  164.         and.l        #SIGBREAKF_CTRL_C,d0
  165.         beq        1$        ; no CTRL-C
  166.  
  167. * remove our view by restoring Intuition's unless our View is no longer active
  168. 3$        move.l        gfxbase(a5),a6
  169.         move.l        gb_ActiView(a6),d0
  170.         beq        8$
  171.         cmp.l        view(a5),d0
  172.         bne        4$        ; our View is no longer active
  173. 8$        move.l        ibase(a5),a6
  174.         jsrlib        ViewAddress    ; get Intuition's View
  175.         move.l        gfxbase(a5),a6
  176.         tst.l        d0        ; did we get it?
  177.         beq        9$        ; Intuition's View unavailable
  178.         move.l        d0,a1
  179.         jsrlib        LoadView    ; load Intuition's View
  180.  
  181. * unblank the mousey (turn sprite DMA back on)
  182. 4$        jsrlib        WaitTOF        ; wait till vertical blank
  183.         SPRITES_ON
  184.  
  185. * free stuff used by our view
  186.         move.l        view(a5),a2
  187.         move.l        v_LOFCprList(a2),a0
  188.         cmp.l        #0,a0
  189.         beq        5$
  190.         jsrlib        FreeCprList
  191. 5$        move.l        v_SHFCprList(a2),a0
  192.         cmp.l        #0,a0
  193.         beq        6$
  194.         jsrlib        FreeCprList
  195. 6$        move.l        v_ViewPort(a2),a2
  196.         move.l        vp_ColorMap(a2),a0
  197.         cmp.l        #0,a0
  198.         beq        7$
  199.         jsrlib        FreeColorMap
  200. 7$        move.l        a2,a0
  201.         jsrlib        FreeVPortCopLists
  202.  
  203. * close graphics.library
  204.         move.l        a6,a1
  205.         jsrsys        CloseLibrary
  206. * close intuition.library
  207.         move.l        ibase(a5),a1
  208.         jsrlib        CloseLibrary
  209.  
  210. * task dies... all MemList-allocated memory gets freed automagically :)
  211. * for now this includes the following structures:
  212. *    View, ViewPort, RasInfo, BitMap
  213. * as well as all of the bitplanes used by the BitMap
  214. * (and of the course the MemList structure itself)
  215.         unlk        a5
  216.         moveq        #0,d0
  217.         rts
  218. kt_end
  219.  
  220.  
  221.  
  222.         SECTION        data,data
  223.  
  224. * mem list to get memory for task stuff
  225. tcbmem        ds.b        LN_SIZE
  226.         dc.w        3
  227. * #1 task stack (and name)
  228.         dc.l        MEMF_PUBLIC|MEMF_CLEAR
  229.         dc.l        STKSIZE+(endname-name)
  230. * #2 Task structure
  231.         dc.l        MEMF_PUBLIC|MEMF_CLEAR
  232.         dc.l        TC_SIZE
  233. * #3 task code segment
  234.         dc.l        MEMF_PUBLIC|MEMF_CLEAR
  235.         dc.l        (kt_end-keeper_task)
  236.  
  237. * name of our task
  238. name        dc.b        "PicKeeper",0
  239. endname
  240.  
  241.         END
  242.